module ContractsHelper
  #查询所有合约的访问路径
  def all_eth_contract_path
    index_routes = []
    Rails.application.routes.routes.each do |route|
      index_url = route.path.spec.to_s
      if index_url.starts_with?('/eth/contracts/') and index_url.include?('/index(.:format)')
        index_name = index_url.split('/')[3].titleize
        index_path = index_url.gsub('(.:format)', '')
        index_routes << {:name => index_name, :path => index_path}
      end
    end
    index_routes
  end

  def url_for_contracts
    index_routes = all_eth_contract_path
    url_str = ''
    index_routes.each do |index|
      url_str += "<li><a href='#{index[:path]}'>#{index[:name]}</a></li>"
    end
    raw url_str
  end
end
